<template>
  <div>
    <!-- :tree-props="{children: '判断是否有子节点的字段'
    default-expand-all 默认展开所有-->
    <!-- {{arr}} -->
    <el-table
      :data="arr"
      style="width: 100%;margin-bottom: 20px;"
      row-key="id"
      border
      :tree-props="{children: 'children'}"
    >
      <el-table-column prop="id" label="规格编号" sortable width="180"></el-table-column>
      <el-table-column prop="specsname" label="规格名称" sortable></el-table-column>
      <el-table-column prop="img" label="规格属性" sortable>
        <template slot-scope="scope">
          <el-tag v-for="item in scope.row.attrs" :key="item">{{item}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="状态" sortable width="180">
        <template slot-scope="scope">
          <el-button v-if="scope.row.status" type="primary">启用</el-button>
          <el-button v-else type="info">禁用</el-button>
        </template>
      </el-table-column>
      <el-table-column prop="name" label="操作" sortable width="180">
        <template slot-scope="scope">
          <el-button type="primary" @click="willUpdate(scope.row.id)">编辑</el-button>
          <el-button type="danger" @click="del(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
      <!-- <el-table-column  label="性别" sortable width="180">
        <template slot-scope="scope">
          {{scope.row.sex==1 ?"男":"女"}}
        </template>
      </el-table-column>-->
    </el-table>
    <!-- 分页 -->
    <el-pagination
    layout="prev,pager,next"
    :total="total"
    :page-size="size"
    @current-change="changePage"
    >
      
    </el-pagination>
  </div>
</template>
<script>
import { mapGetters, mapActions } from "vuex";
import { reqspecsdelete } from "../../../http/api";
import { successAlert } from "../../../utils/alert";
export default {
  computed: {
    ...mapGetters({
      arr: "specs/arr",
      size:"specs/size",
      total:"specs/total"
    })
  },
  mounted() {
    //一进来就做请求
    this.reqArr();
  },
  methods: {
    ...mapActions({
      reqArr: "specs/reqArr",
      changePage:"specs/changePage"
    }),
    //点击编辑
    willUpdate(id) {
      this.$emit("willUpdate", id);
    },
    //点了删除
    del(id) {
      this.$confirm("你确定要删除吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          //删除的请求
          reqspecsdelete({ id: id }).then(res => {
            if (res.data.code == 200) {
              //弹成功
              successAlert(res.data.msg);
              //刷列表
              this.reqArr()
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    }
  }
};
</script>
<style scoped lang="less">
@import "../../../less/index.less";
img{
  width: 50px;
  height: 50px;
}
</style>